package com.yunhe.tianhe.rentcars.controller.cheliangguanli;


import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.XinXi;
import com.yunhe.tianhe.rentcars.entity.system.Dept;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.XinXiService;
import com.yunhe.tianhe.rentcars.service.system.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/xinxi")
public class XinXiController {
    @Autowired
    private XinXiService xinXiService;
    @Autowired
    private DeptService deptService;


    @RequestMapping("/list")
    public String list(){
        return "cheliangguanli/xinxi/xinxilist";
    }

    @ResponseBody
    @RequestMapping("/listData")
    public Pageable<XinXi> listdata(Integer offset, Integer limit,String carcode,Integer carstate){
        Pageable page = xinXiService.findPage(offset, limit,carcode,carstate);
        return page;
    }

    @RequestMapping("/add")
    public String add(HttpServletRequest req){
        List<Dept> list = deptService.findList();
        req.getSession().setAttribute("dept",list);
        return "cheliangguanli/xinxi/xinxiadd";
    }

    @RequestMapping("/save")
    public String save(XinXi xinXi){
        xinXiService.save(xinXi);
        return "cheliangguanli/xinxi/xinxilist";
    }

    @RequestMapping("/deletebatch")
    @ResponseBody
    public String deletebatch(String carids){
        xinXiService.deletebatch(carids);
        return "删除成功";
    }


    @RequestMapping("/update")

    public String update(HttpServletRequest req,long carid){
        XinXi xinXi = xinXiService.find(carid);
        List<Dept> list = deptService.findList();
        req.getSession().setAttribute("dept",list);
        req.getSession().setAttribute("xinxi",xinXi);
        return "cheliangguanli/xinxi/xinxiupdate";
    }

    @RequestMapping("/resave")
    public String resave(XinXi xinXi){
        xinXiService.update(xinXi);
        return "cheliangguanli/xinxi/xinxilist";
    }

}
